package com.mypack.crm.controller.account;

import com.github.pagehelper.PageInfo;
import com.mypack.crm.context.SessionContext;
import com.mypack.crm.dto.account.AccountDTO;
import com.mypack.crm.dto.account.AccountSearchDTO;
import com.mypack.crm.service.account.AccountService;
import com.mypack.crm.utils.Result;
import com.mypack.crm.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/account")
public class AccountController {


    @Autowired
    private AccountService accountService;

    /**
     * 查询账号信息
     */
    @RequestMapping("/list")
    public Result list(@RequestBody AccountSearchDTO searchDTO) {

        List<AccountDTO> accountDTOList = accountService.listAccount(searchDTO, true);

        accountDTOList.forEach(item->item.setPassword(null));

        PageInfo pageInfo = new PageInfo(accountDTOList);

        return ResultUtils.success(pageInfo);
    }

    /**
     * 查询账号信息
     */
    @RequestMapping("/query")
    public Result query() {
        AccountDTO accountDTO = SessionContext.getCurrentUser();
        accountDTO.setPassword(null);
        return ResultUtils.success(SessionContext.getCurrentUser());
    }

}
